package conson.tech.manage.facade.controller.scene;

import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.scene.service.DictionaryService;
import conson.tech.manage.scene.vo.request.DictionaryRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description: 字典服务
 * @author: yuwenshuo
 * @since: 2020-06-22 09:58
 */

@Api(value = "字典服务，教培等系统使用",tags = "字典服务，教培等系统使用")
@RestController
@RequestMapping((SecurityConstants.MANAGERAPI + "/dictionary"))
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    @ApiOperation(value = "字典保存", notes = "字典新增及修改")
    @ApiImplicitParam(name = "dictionaryRequest", value = "请求入参", required = true, dataType = "DictionaryRequest")
    @PostMapping("/save")
    public Response save(@RequestBody DictionaryRequest dictionaryRequest, HttpServletRequest request) {

        String operationUser = request.getHeader("user_name");

        dictionaryService.save(dictionaryRequest, operationUser);

        return Response.success();
    }

    @ApiOperation(value = "字典删除", notes = "字典删除")
    @ApiImplicitParam(name = "dictionaryRequest", value = "请求入参", required = true, dataType = "DictionaryRequest")
    @PostMapping("/delete")
    public Response delete(@RequestBody DictionaryRequest dictionaryRequest, HttpServletRequest request) {

        String operationUser = request.getHeader("user_name");

        dictionaryService.delete(dictionaryRequest.getId(), operationUser);

        return Response.success();
    }

    @ApiOperation(value = "字典查询", notes = "字典查询")
    @ApiImplicitParam(name = "dictionaryRequest", value = "请求入参", required = true, dataType = "DictionaryRequest")
    @PostMapping("/query")
    public Response query(@RequestBody DictionaryRequest dictionaryRequest, HttpServletRequest request) {

        return Response.success(dictionaryService.getDictionaryByParam(dictionaryRequest));
    }


    @ApiOperation(value = "字典冻结", notes = "字典冻结")
    @ApiImplicitParam(name = "dictionaryRequest", value = "请求入参", required = true, dataType = "DictionaryRequest")
    @PostMapping("/lock")
    public Response lock(@RequestBody DictionaryRequest dictionaryRequest, HttpServletRequest request) {

        String operationUser = request.getHeader("user_name");

        dictionaryService.lock(dictionaryRequest.getId(), operationUser);

        return Response.success();
    }

    @ApiOperation(value = "字典解冻", notes = "字典解冻")
    @ApiImplicitParam(name = "dictionaryRequest", value = "请求入参", required = true, dataType = "DictionaryRequest")
    @PostMapping("/unlock")
    public Response unlock(@RequestBody DictionaryRequest dictionaryRequest, HttpServletRequest request) {

        String operationUser = request.getHeader("user_name");

        dictionaryService.unlock(dictionaryRequest.getId(), operationUser);

        return Response.success();
    }

}
